package org.example.goods.controller;

import org.example.entity.Goods;
import org.example.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @GetMapping("/{id}")
    public Goods queryGoods(@PathVariable("id") Long id) {
        return goodsService.findGoodsById(id);
    }

    @GetMapping("/reduceGoods")
    public String reduceGoods(@RequestParam("id") Long id, @RequestParam("amount") Integer amount) {
        goodsService.reduceGoodsStock(id, amount);
        return "ok";
    }
}
